import { create } from "zustand";

// 定义 store 状态类型
interface CounterState {
  count: number;
  title: string;
  increment: () => void;
  decrement: () => void;
  reset: () => void;
  setTitle: (title: string) => void;
}

// 创建 store
export const useCounterStore = create<CounterState>((set) => ({
  count: 0,
  title: "Zustand 计数器示例",
  increment: () => set((state) => ({ count: state.count + 1 })),
  decrement: () => set((state) => ({ count: state.count - 1 })),
  reset: () => set({ count: 0 }),
  setTitle: (title: string) => set({ title }),
}));
